
public class Rayon {
	
	private ObjetNourriture buffer[];
	private int sizeMax;
	private int lire, ecrire;
	private int nbElmt;
	private int temps;
	private String nom;
	
	Rayon(int max, int temps, String nom){
		this.buffer = new ObjetNourriture[max];
		this.sizeMax = max;
		this.lire = this.ecrire = this.nbElmt = 0;
		this.temps = temps; 
		this.nom = nom;
	}
	
	
	public String getNom() {
		return nom;
	}

	public int getTemps() {
		return temps;
	}

	public int getNbElmt() {
		return nbElmt;
	}

	synchronized void Put(ObjetNourriture h){
		while (this.nbElmt == this.sizeMax)
		try {
			wait();
		} catch (InterruptedException e) {
		e.printStackTrace();
		}
		
		this.buffer[this.ecrire++] = h;
		notifyAll();
		nbElmt++;
		this.ecrire %= this.sizeMax;
		}
	
	synchronized ObjetNourriture Get(){
		while (this.nbElmt == 0)
			try {
				wait();
			} catch (InterruptedException e) {
			e.printStackTrace();
			}
		
		ObjetNourriture h = this.buffer[this.lire++];
		this.lire %= this.sizeMax;
		notifyAll();
		nbElmt--;
		return h;
	}
}

